package main

import (
	"fmt"
	"os"
	"os/exec"
	// "strings"
)

func main() {
	// var cmds = [...]string{"ls", "-al" }
	// fmt.Println(cmds)
	// install ipfs
	// newpath := filepath.Join(".", "public")
	err := os.MkdirAll("../.cache", os.ModePerm)
	if err != nil {
		fmt.Println("Unable to create folder: ", err.Error())
	}
	result, err := exec.Command("tar", "-C", "../.cache/", "-xvzf", "./IPFS/go-ipfs_v0.12.0_linux-amd64.tar.gz").Output()
	fmt.Printf("%s", result)
	if err != nil {
		fmt.Println("Extract failed:", err.Error())
	}
	result, err = exec.Command("sudo", "/bin/sh", "../.cache/go-ipfs/install.sh").Output()
	fmt.Printf("%s", result)
	if err != nil {
		fmt.Println("Move failed:", err.Error())
	}

	result, err = exec.Command("ipfs", "init").Output()
	fmt.Printf("%s", result)
	if err != nil {
		fmt.Println("Init failed:", err.Error())
	}

	cmd := exec.Command("ipfs", "daemon")
	err = cmd.Start()
	if err != nil {
		fmt.Println("Start daemon failed:", err.Error())
	}
	fmt.Printf("Just ran subprocess %d, exiting\n", cmd.Process.Pid)
}
